<?php
/**
 *	[TWCMS] (C)2012 TongWang Inc.
 *	$Id: tool_cache.php 2 2013-04-27 07:14:17Z nanown@qq.com $
 */
class tool_cache extends admin{
	function __construct() {
		parent::__construct();
		$this->main();
	}

	function main() {
		if(!empty($_GET['do']) && $_GET['do'] == 'ajax_clear') {
			$this->clearCache();
		}else{
			include load_tpl(__CLASS__);
		}
	}

	#清除缓存目录
	function clearCache() {
		$err = 1;
		$pathArr = array('datacache'=>TWCMS_CACHE, 'tplcache'=>TWCMS_TPLCACHE);
		if(!empty($_POST['doarr']) && is_array($_POST['doarr'])) {
			$err = 0;
			foreach($_POST['doarr'] as $val) {
				if(in_array($val, array('datacache', 'tplcache'))) {
					if(!un_cache($pathArr[$val])) $err = 1;
				}
			}
		}
		$msg = empty($err) ? '清除完成' : '清除出错';
		exit('{"err":'.$err.',"msg":"'.$msg.'"}');
	}
}